Ext.define('Admin.view.sys.DdsMConsecController', {
	extend: 'Ext.app.ViewController',
	alias: 'controller.ddsMConsecController',
	init: function () {
	},

	//状态管理
	state: {
		// refs: this.getReferences(), //所有的references的集合
	},

	//河流搜索
	riverSearch: function () {
		var refs = this.getReferences();
		// var serchName = refs.serchName.getValue();
		var serchRcd = refs.serchRcd.getValue();
		var grid = refs.riverMCGrid;
		var params = { rcd: serchRcd,river:config.RIVER };
		grid.getStore().getProxy().extraParams = params;
		grid.getStore().reload();
	},

	//删除
	riverDelete: function (grid, rowIndex, colIndex) {
		var rcd = grid.getStore().getAt(rowIndex).get('rcd');
		var secid = grid.getStore().getAt(rowIndex).get('secid');
		// var bname = grid.getStore().getAt(rowIndex).get('bname');
		Ext.Msg.confirm("警告", "确定要删除吗？", function (button) {
			if (button === 'yes') {
				Ext.Ajax.request({
					url: config.URL + 'emergency/ddsmconsec/delete',
					method: "post",
					success: function (response, opts) {
						Ext.MessageBox.hide();
						var result = Ext.JSON.decode(response.responseText);
						if (result.code === 1) {
							grid.store.load();
							Ext.Msg.alert('系统提示', "删除成功");
						} else {
							Ext.Msg.alert("系统提示", result.msg);
						}
					},
					failure: function () {
						Ext.Msg.alert('系统提示', '系统出错！');
					},
					params: { rcd: rcd,secid: secid, river:config.RIVER }
				});
			}
		})
	},

	//新增
	riverAdd: function () {
		var _that = this;
		// var win = Ext.ComponentQuery.query('#expertAddWindow')[0];
		var win = _that.lookupReference('expertAddWindow');
		if (!win) {
			win = Ext.create('Ext.window.Window', {
				title: '新增模型控制断面',
				width: 530,
				layout: 'fit',
//				modal: false,
				autoScroll: true,
				closeAction: 'hide',
				reference: 'expertAddWindow',
				buttons: [

					{
						text: '保存',
						handler: function () {
							var form = _that.lookupReference('expertAddForm').getForm();
							var modal = this.up('window');
							var expertGrid = _that.lookupReference('riverMCGrid');
							var store = expertGrid.getStore();
							var values = form.getValues();
							values.river = config.RIVER;
							Ext.Ajax.request({
								url: config.URL + 'emergency/ddsmconsec/save',
								method: "post",
								success: function (response, opts) {
									var result = Ext.JSON.decode(response.responseText);
									Ext.MessageBox.hide();
									if (result.code === 1) {
										Ext.Msg.alert('系统提示', "保存成功");
										store.reload();
										modal.hide();
									} else {
										Ext.Msg.alert("系统提示", result.msg);
									}
								},
								failure: function () {
									Ext.Msg.alert('系统提示', '系统出错！');
								},
								params: values
							});
						}
					},
					{
						text: '取消',
						handler: function () {
							var modal = this.up('window');
							modal.hide()
						}
					},
				],
				items: {
					xtype: 'riverMCForm',
					border: false,
					reference: 'expertAddForm'
				}
			})
			this.getView().add(win)
		}
		win.show();
		this.lookupReference('expertAddForm').getForm().reset();
	},

	//修改
	riverUpdate: function (grid, rowIndex, colIndex) {
		var rec = grid.getStore().getAt(rowIndex);
		var _that = this;
		var win = this.lookupReference('expertUpdataWindow');
		var saveUpdata = function () {
			var form = _that.lookupReference('expertUpdataForm').getForm();
			var modal = this.up('window');
			var emergencyIncidentGrid = _that.lookupReference('riverMCGrid');
			var store = emergencyIncidentGrid.getStore();
			var values = form.getValues();
			values.river = config.RIVER;
			Ext.Ajax.request({
				url: config.URL + 'emergency/ddsmconsec/update',
				method: "post",
				success: function (response, opts) {
					Ext.MessageBox.hide();
					var result = Ext.JSON.decode(response.responseText);
					if (result.code === 1) {
						Ext.Msg.alert('系统提示', "修改成功");
						store.reload();
						modal.hide();
					} else {
						Ext.Msg.alert("系统提示", result.msg);
					}
				},
				failure: function () {
					Ext.Msg.alert('系统提示', '系统出错！');
				},
				params: values
			});
		};
		if (!win) {
			win = Ext.create('Ext.window.Window', {
				title: '修改模型控制断面',
				width: 530,
				layout: 'fit',
//				modal: false,
				autoScroll: true,
				closeAction: 'hide',
				reference: 'expertUpdataWindow',
				buttons: [
					{
						text: '保存',
						handler: saveUpdata
					},
					{
						text: '取消',
						handler: function () {
							var modal = this.up('window');
							_that.lookupReference('expertUpdataForm').getForm().reset();
							modal.hide()
						}
					},

				],
				items: {
					xtype: 'riverMCForm',
					border: false,
					reference: 'expertUpdataForm'
				}
			});
			this.getView().add(win);
		}
		this.lookupReference('expertUpdataForm').getForm().reset();
		this.lookupReference('expertUpdataForm').getForm().setValues(rec.data)
		win.show();

	}

});
